<template>
	<div style="width: 100%;">
		<van-row style="width: 100%;height: 8vh;line-height: 8vh;">
			<van-col span="3">
				<van-icon name="arrow-left" size="25" style="margin-top: 15px;" @click="backhead" />
			</van-col>
			<van-col span="16" style="margin-left: 2%;height: 8vh;">
				<van-search v-model="value" shape="round" background="#fff" placeholder="苹果电脑"
					style="margin-top: 3px;" />
			</van-col>
			<van-col span="3" style="height: 8vh;">
				<button
					style="border: 0px;background-color: #FFFFFF; width: 100%;height: 8vh;line-height: 8vh;text-align: center;font-size: 16px;"
					@click="searchmenu">
					搜索
				</button>
			</van-col>
		</van-row>
		<van-row style="width: 100%;height: 6vh;line-height: 6vh;">
			<van-col span="24"
				style="width: 100%;height: 6vh;font-weight: 600;font-size: 18px;text-align: left;padding-left: 3%;">
				热搜
			</van-col>
		</van-row>
		<Searchlist :brief="brief"></Searchlist>
		<Searchmenu :list="list"></Searchmenu>
	</div>
</template>

<script>
	import Searchlist from '@/components/searchinput/Searchlist.vue'
	import Searchmenu from '@/components/searchinput/Searchmenu.vue'
	export default {
		components: {
			Searchlist,
			Searchmenu
		},
		data() {
			return {
				value: '',
				list: [],
				brief:[],
				keywords:''
			}
		},
		created() {

		},
		methods: {
			backhead() {
				this.$router.push({path:'/'})
			},
			searchmenu() {
				// this.$router.push({path:'/searchcart'})
				let value = this.value
				this.$store.dispatch("vuexSearchcart", value)
					.then(e => {
						console.log(e)
						this.list = e.data.data
					})
				if (this.value !== '') {
					let val = this.value.trim() //输入的值去除字符串的头尾空格

					this.show = false
					if (!val) {
						// 判断输入框的值是否为空
						return
					}

					if (this.brief.indexOf(val) === -1) {//查找
						this.brief.unshift(val) //最新的第一个历史记录，头部添加
						this.brief = this.brief.slice(0, 10) //最多显示10个
						// 历史记录的搜索
						localStorage.setItem('history', JSON.stringify(this.brief))//转换为json形式的字符串
					}
				}

			}
		}
	}
</script>

<style>
</style>
